﻿using System;
using EnvDTE;
using EnvDTE80;

namespace ForgeIt.Commands
{
    class ProjectCommand : BaseCommand
    {

        public ProjectCommand(DTE2 applicationObject, Connect connectorClass):base(applicationObject, connectorClass)
        {
            validExtensions.Add(".csproj");
        }

        public override void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
        {
            var project = (Array)ApplicationObject.ActiveSolutionProjects;
            if (project.Length == 1)
            {
               // TODO: Implement forms
            }
            else
            {
                Log("Selected: " + project.Length, true);
            }
        }

        public override void QueryStatus(string CmdName, vsCommandStatusTextWanted NeededText, ref vsCommandStatus StatusOption, ref object CommandText)
        {
            try
            {
                Array project = (Array) ApplicationObject.ActiveSolutionProjects;
                StatusOption = project.Length == 1 ? StatusEnabled : StatusInvisible;
                //if (project.Length == 1)
                //{
                //    ConnectorClass.Log("Project FileName: " + ((Project) project.GetValue(0)).FileName);
                //    ConnectorClass.Log("Project FullName: " + ((Project) project.GetValue(0)).FullName);
                //    ConnectorClass.Log("Project UniqueName: " + ((Project) project.GetValue(0)).UniqueName);
                //}
            }
            catch (Exception)
            {
                StatusOption = StatusInvisible;
            }
        }
    }
}
